namespace Legend.Core.Tests.Caching.PurgedInMemoryCacheTests
{
    using System;
    using Legend.Caching;
    using NUnit.Framework;
    using Legend.Tests;

    [TestFixture]
    public class CacheExtensionsTests
    {
        private ObjectCacheAdaptor cache;

        [SetUp]
        public void SetUp()
        {
            this.cache = new ObjectCacheAdaptor();
        }

        [Test]
        public void GetValueOrDefault_should_return_null_when_value_does_not_exist()
        {
            // Arrange
            
            // Act

            // Assert
            Assert.That(this.cache.GetValueOrDefault<object>("key"), Is.Null);
        }

        [Test]
        public void GetValueOrDefault_should_return_value_when_value_exists()
        {
            // Arrange
            this.cache.Insert("key", 10, TimeSpan.FromMinutes(1));

            // Act

            // Assert
            Assert.That(this.cache.GetValueOrDefault<int>("key"), Is.EqualTo(10));
        }

        [Test]
        public void GetValueOrDefault_should_be_null_guarded()
        {
            // Arrange

            // Act

            // Assert
            NullGuardedConstraint.Assert(() =>
                Cache.GetValueOrDefault<int>(this.cache, "key"));
        }
    }
}
